package com.yxlgateway.service.impl;

import com.yxlgateway.service.EmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author: yxl
 * @since: 2021-11-16
 **/
@Service
@Slf4j
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    @Override
    public void sendRegisterCode(String to, String text) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(from);
        mailMessage.setTo(to);
        mailMessage.setSubject("注册验证码");
        mailMessage.setText(text);
        javaMailSender.send(mailMessage);

    }

    @Override
    public void sendFindPasswordCode(String to, String text) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setSubject("找回密码验证码");
        mailMessage.setText(text);
        mailMessage.setTo(to);
        mailMessage.setFrom(from);
        javaMailSender.send(mailMessage);
    }

    @Override
    public void sendChangePasswordCode(String to, String text) {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(from);
        mailMessage.setTo(to);
        mailMessage.setText(text);
        mailMessage.setSubject("更改密码验证码");
        javaMailSender.send(mailMessage);
    }
}
